﻿using System;

using Microsoft.Xna.Framework;

namespace Ah.Testudin.Engine.Processes
{
    public abstract class ProcessBase : IProcess
    {
        #region Private Member Variables

        protected ProcessState _state;

        #endregion

        #region Properties

        #endregion

        #region Constructors

        public ProcessBase()
            : this(null)
        {
        }

        public ProcessBase(IProcess childProcess)
        {
            this.ChildProcess = childProcess;
        }

        #endregion

        #region IProcess

        public IProcess ChildProcess { get; private set; }

        public ProcessState State
        {
            get { return _state; }

            set { _state = value; }
        }

        public bool IsDead
        {
            get
            {
                return _state == ProcessState.Succeeded ||
                       _state == ProcessState.Failed ||
                       _state == ProcessState.Aborted ||
                       _state == ProcessState.Removed;
            }
        }

        public virtual void Initialize()
        {
            _state = ProcessState.Running;
        }

        public abstract void Update(GameTime gameTime);

        public virtual void Abort()
        {
            _state = ProcessState.Aborted;
        }

        #endregion
    }
}
